<?php
class PostHelper extends AppHelper {
        function pre($content = null, $params = array('cut'=>'cut')) {
		$content = preg_replace('/\r\n/', '<br />', $content);

		$patern = '/(.*)(<rhcut>)(.*)(<\/rhcut>)(.*)/';
		preg_match($patern, $content, $parts);
		#pr ($parts);
		if (!empty($parts)) {
			$content = $parts[1];

			if ($params['cut'] === 'cut') {
				$content .= '<a href="'. $params['link'] .'">'. $parts[3] .'</a>';
			} elseif ($params['cut'] === 'full') {
				$content .= '<a name="rhcut"></a>';
				$content .= $parts[5];
			}
		}
		return $this->output($content);
        }

        function createMenu($menu=array(), $class='') {
                if (is_array($menu)) {
                        $class = (!empty($class))? ' class="'.$class.'"' : '';
                        $htMenu = '<ul'.$class.'>' . "\n";
                        foreach($menu as $k => $v) {
                                $liClass = (isset($v['class']))? ' class="'.$v['class'].'"': '';
                                $htMenu .= '<li'.$liClass.'>';
                                $htMenu .= '<a href="'.$v['url'].'/">'.$v['name'].'</a>' . "\n";
                                if (isset($v['sub'])) {
                                        $subClass = (isset($v['subClass']))? $v['subClass'] : '' ;
                                        $htMenu .= $this->createMenu($v['sub'], $subClass);
                                }
                                $htMenu .= '</li>' . "\n";
                        }
                        $htMenu .= '</ul>' . "\n";
                        return $this->output($htMenu);
                }

        }

	function tags($tags = null, $controller = null) {
		if ($tags && $controller) {
			$tags = explode(', ', $tags);
			$html = '';
			foreach ($tags as $tag) {
				$html .= '<a href="/'. $controller .'/tags/'. $tag .'/">'. $tag  .'</a> ';
			}	
			return $this->output($html);
		}
	}


	function trasnlite($st) {

		$chars = array(
			'а'=>'a', 'б'=>'b', 'в'=>'v', 'г'=>'g', 'д'=>'d', 'е'=>'e', 'ё'=>'ya', 'ж'=>'zh',
			'з'=>'z', 'и'=>'i', 'й'=>'y', 'к'=>'k', 'л'=>'l', 'м'=>'m', 'н'=>'n', 'о'=>'o', 'п'=>'p',
			'р'=>'r', 'с'=>'s', 'т'=>'t', 'у'=>'u', 'ф'=>'f', 'х'=>'h', 'ц'=>'ts', 'ч'=>'ch', 'ш'=>'sh',
			'щ'=>'shch', 'ъ'=>'', 'ы'=>'y', 'ь'=>'', 'э'=>'e', 'ю'=>'u', 'я'=>'ya',
			'А'=>'A', 'Б'=>'B', 'В'=>'V', 'Г'=>'G', 'Д'=>'D', 'Е'=>'E', 'Ё'=>'YA', 'Ж'=>'ZH',
			'З'=>'Z', 'И'=>'I', 'Й'=>'Y', 'К'=>'K', 'Л'=>'L', 'М'=>'M', 'Н'=>'N', 'О'=>'O', 'П'=>'P',
			'Р'=>'R', 'С'=>'S', 'Т'=>'T', 'У'=>'U', 'Ф'=>'F', 'Х'=>'H', 'Ц'=>'TS', 'Ч'=>'CH', 'Ш'=>'SH',
			'Щ'=>'SHCH', 'Ъ'=>'', 'Ы'=>'Y', 'Ь'=>'', 'Э'=>'E', 'Ю'=>'U', 'Я'=>'YA'
		);

		$st = str_replace(array_keys($chars), array_values($chars), $st);

		return $this->output($st);

	}
}
?>
